from threading import  Thread,Lock
class StoppableThread(Thread):
    def __init__(self):
        Thread.__init__(self)
        self._terminate=False
        self._suspend_lock=Lock()

    def terminate(self):
        self._terminate=True

    def suspend(self):
        self._suspend_lock.acquire()

    def resume(self):
        self._suspend_lock.release()

    def run(self):
        while True:
            if self._terminate:
                break
            self._suspend_lock.acquire()
            self._suspend_lock.release()
            ...